/* 
 * Copyright 2011 kOSMik.
 * This file is part of kOSMik.
 * 
 * kOSMik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * kOSMik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * kOSMik:
 * Open Street Map - Editor.
 * http://code.google.com/p/swp-dv-ws2010-osm-2/
 */

package de.fuberlin.kosmik.data.osmt;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * This interface is used to access the osmt database.
 * 
 * @author Johannes
 * 
 */
public interface OsmtData {

	/**
	 * Delivers the listener a cursor to a full query of the feature table.
	 * 
	 * @param onObtainCursorListener that handles the query result
	 */
	void traverseAllFeatures(OnObtainCursorListener onObtainCursorListener);

	/**
	 * Fetches all features into a given collection object filtered by a search
	 * word and by element type.
	 * 
	 * @param searchTerm The term that all features should match
	 * @param filterElements The element types that should be considered in the
	 *            search
	 * 
	 * @return a collection with all features that match the search term
	 */
	Collection<OsmtFeatureRecord> fetchAllFeaturesThatMatches(String searchTerm,
			int filterElements);

	/**
	 * Fetches all bundles into a given collection object filtered by a search
	 * word and by element type.
	 * 
	 * @param searchTerm The term that all features should match
	 * @param filterElements The element types that should be considered in the
	 *            search
	 * 
	 * @return a collection with all features that match the search term
	 */
	Collection<OsmtNodeRecord> fetchAllBundlesThatMatches(String searchTerm, int filterElements);

	/**
	 * Fetches all themes into a given collection object filtered by a search
	 * word and by element type.
	 * 
	 * @param searchTerm The term that all features should match
	 * @param filterElements The element types that should be considered in the
	 *            search
	 * 
	 * @return a collection with all features that match the search term
	 */
	Collection<OsmtNodeRecord> fetchAllThemesThatMatches(String searchTerm, int filterElements);

	/**
	 * Fetches all child id's arranged according to its degree of use with the
	 * specified id are assigned to parents directly.
	 * 
	 * The nodes are filtered by elements attributes poi,way or area.
	 * Furthermore, the returned array of node id's will be ordered by frequency
	 * of usage.
	 * 
	 * @param parentId The id of node, that is parent to all items in the
	 *            returned list. if parentId is 0, all root nodes will be
	 *            returned.
	 * @param filterElements the result set should be filtered.
	 * @return All child nodes of the node with the passed parent id.
	 */
	List<Integer> fetchAllIdsOfChildNodesRelatedToParentIdFilteredByElements(int parentId,
			int filterElements);

	/**
	 * Fetches all in database stored information about the child nodes related
	 * to the given parent id.
	 * 
	 * The nodes are filtered by elements attributes poi,way or area.
	 * Furthermore, the returned array of node id's will be ordered by frequency
	 * of usage.
	 * 
	 * @param parentId The id of node, that is parent to all items in the
	 *            returned list. if parentId is 0, all root nodes will be
	 *            returned.
	 * @param filterElements the result set should be filtered.
	 * @return All child nodes of the node with the passed parent id.
	 */
	Map<Integer, OsmtNodeRecord> fetchAllChildNodesRelatedToParentIdFilteredByElements(
			int parentId, int filterElements);

	/**
	 * Fetches all features from the Osmt database that are related to the node
	 * with the given id.
	 * 
	 * @param bundleId The id of the node you wish to fetch all related
	 *            features.
	 * 
	 * @return All related features in delivered in a <code>ArrayList</code>
	 */
	List<OsmtFeatureRecord> fetchAllFeaturesOfBundleWithId(int bundleId);

	/**
	 * Fetches a list of all keys that are contain in the database.
	 * 
	 * The list is ordered first by times of usage and second alphabetical.
	 * 
	 * @return the list with all keys.
	 */
	List<OsmtKeyRecord> fetchAllKeys();

	/**
	 * Fetches a list of all values that are contain in the database related to
	 * the passed key.
	 * 
	 * The list is ordered first by times of usage and second alphabetical.
	 * 
	 * @param keyName The key the values should be related to.
	 * 
	 * @return the list with all keys.
	 */
	List<OsmtValueRecord> fetchAllValuesForKey(String keyName);

}
